using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Model.Business;
using ZR.Repository;
using ZR.Service.Business.IBusinessService;
using System.Linq;

namespace ZR.Service.Business
{
    /// <summary>
    /// 学生表Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(IAStudentService), ServiceLifetime = LifeTime.Transient)]
    //[Component]
    public class AStudentService : BaseService<AStudent>, IAStudentService
    {
        /// <summary>
        /// 查询学生表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<AStudentDto> GetList(AStudentQueryDto parm)
        {
            var predicate = Expressionable.Create<AStudent>();
            predicate.AndIF(!string.IsNullOrEmpty(parm.StuName), t => t.StuName.Contains(parm.StuName));

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<AStudent, AStudentDto>(parm);

            return response;
        }


        /// <summary>
        /// 添加学生表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddAStudent(AStudent model)
        {
            return Add(model, true);
        }

        /// <summary>
        /// 修改学生表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateAStudent(AStudent model)
        {
            //var response = Update(w => w.Id == model.Id, it => new AStudent()
            //{
            //    StdName = model.StdName,
            //    StdSex = model.StdSex,
            //    StdAge = model.StdAge,
            //    Remark = model.Remark,
            //});
            //return response;
            return Update(model, true);
        }
    }
}